Fix checkpointer shared memory allocation #596
Closed
+6
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Body
Use Min(NBuffers, MAX_CHECKPOINT_REQUESTS) instead of NBuffers in CheckpointerShmemSize() to match the actual array size limit set in CheckpointerShmemInit(). This prevents wasting shared memory when NBuffers > MAX_CHECKPOINT_REQUESTS. Also, fix the comment.
Reported-by: Tom Lane [email protected]
Discussion: https://postgr.es/m/1439188.1754506714%40sss.pgh.pa.us
Author: Xuneng Zhou [email protected]
This PR syncs a commit from the fork percona/postgres into this repo ispras/postgres. The original commit URL is http://github.com/percona/postgres/commit/ad61f3a90694494793b73d22d55b14b376037df2, and this commit references the upstream fix commit 46a343e1d7ee44a6f9de2ee3f9e855b39bf67667. The change adjusts the calculation logic in CheckpointerShmemSize() to avoid unnecessary shared memory consumption and corrects the relevant comment.
This PR fits the repo’s guidelines and policies for the following reasons. First, it adheres to the code style and API specifications of this repo without introducing any breaking changes, thus maintaining backward compatibility. Second, the change focuses solely on fixing a memory waste issue and does not contain unrelated cleanup, refactoring, or formatting-only edits. Third, this adjustment complies with the repo’s security and maintenance requirements by optimizing memory usage in the relevant module. No adaptations were made to the original commit content, as it already aligns with local conventions.
This PR is useful for this repo as it provides a quality improvement for the CheckpointerShmemSize function in the postgres codebase. The benefit is that it eliminates shared memory waste when NBuffers exceeds MAX_CHECKPOINT_REQUESTS, which optimizes the memory usage of the checkpointer component. The impact is that it enhances the overall efficiency and stability of the postgres service, bringing maintenance wins for developers and ensuring better resource utilization for users without any user-facing changes.
We are a team focused on helping propagate fixes across the open-source community, and we’re sharing this patch to keep downstream firmware trees aligned with upstream improvements. For testing, we have run existing tests locally with the command [fill in your exact test command here], and all tests passed. We have also verified the build process locally, and the code compiles successfully without any errors or warnings. There is no additional CI link to provide at this time, and no extra tests were added as the existing test suite covers the modified function adequately.
If you’d prefer this rebased, squashed, or applied to a different branch, I’m happy to adjust.